package net.crowdloud.server.DatabaseAccess.tags;

import java.util.List;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class GetTags {

	public static net.crowdloud.shared.entities.Tags get(
			PersistenceManager persistenceManager) {

		Tags tagsDatabase = getTagsDatabase(persistenceManager);

		net.crowdloud.shared.entities.Tags tags = ConvertDatabaseToTag
				.getTag(tagsDatabase);

		return tags;
	}

	public static Tags getTagsDatabase(PersistenceManager persistenceManager) {

		Extent extent = persistenceManager.getExtent(Tags.class, true);

		Query query = persistenceManager.newQuery(extent);

		List<Tags> tagsDatabase = (List<Tags>) query.execute("");

		if (tagsDatabase == null || tagsDatabase.size() == 0) {

			// SaveTags.addNew(
			// persistenceManager,
			// "Java, JavaScript, GWT, Logo, Amazon Cloud, EC2,"
			// + " GAE, Eclipse, PHP, Ruby, Web Design, Tester,"
			// + " Customer Development, Business Development, Marketing");

			return null;
		} else {

			return tagsDatabase.get(0);
		}
	}

}
